/**
 * 
 */
package com.nari.basic.action;

import java.util.List;

import org.apache.struts2.json.JSONUtil;
import org.apache.struts2.json.annotations.JSON;

import com.nari.basic.model.IRole;
import com.nari.basic.service.IBasicResourceCascadeMgrService;
import com.nari.basic.service.IRoleMenuService;
import com.nari.basic.service.IRoleService;
import com.nari.basic.service.IUserRoleService;
import com.nari.coreframe.action.struts2.JSONActionSupport;
import com.nari.platform.model.ResponseMsg;
import com.opensymphony.xwork2.Action;

/**
 * 
 * @author Xiaopeng
 * @date 2013-7-18
 */
public class RoleAction extends JSONActionSupport {
	private static final long serialVersionUID = 3267025277767158067L;
	private IRoleService iRoleService;
	private IRoleMenuService iRoleMenuService;
	private IUserRoleService iUserRoleService;
	private IBasicResourceCascadeMgrService iBasicResourceCascadeMgrService;
	//角色列表查询
	private String roleID;
	private String roleName;
	private List<IRole> roleList;
	//角色信息管理
	private String roleUID;
	private IRole role;
	
	/**
	 * 系统权限管理导航
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-3-26
	 */
	public String queryRoleAuthorityMgrNav() throws Exception {
		//便于系统参数携带
		return "roleAuthorityMgrNav";
	}
	
	/**
	 * 查询系统角色列表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-7-26
	 */
	public String queryRoleList() throws Exception {
		this.roleList = this.iRoleService.queryRoleInOrder(roleID, roleName);
		return "roleList";
	}
	
	/**
	 * 角色信息管理
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-7-26
	 */
	public String queryRoleForManage() throws Exception {
		if(this.roleUID!=null && !"".equals(this.roleUID.trim())) {
			this.role = this.iRoleService.queryEntityById(roleUID);
		}
		return "roleManage";
	}
	
	/**
	 * 新增或修改角色信息
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-7-26
	 */
	public String saveOrUpdateRole() throws Exception {
		if(role.getId()!=null && !"".equals(role.getId().trim())) {
			this.iRoleService.updateEntity(role, role.getId());
		} else {
			this.iRoleService.saveEntity(role);
		}
		this.writeJsonStrToResponse(JSONUtil.serialize(ResponseMsg.getInstance(true, "")));
		return Action.SUCCESS;
	}
	
	/**
	 * 根据角色唯一标识删除角色信息
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-7-26
	 */
	public String deleteRoleByRoleUID() throws Exception {
		this.rmsg = iBasicResourceCascadeMgrService.deleteRoleCascadeByRoleUID(roleUID);
		this.writeJsonStrToResponse(JSONUtil.serialize(rmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * 角色授权列表初始化
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-7-26
	 */
	public String initialRoleAuthorize() throws Exception {
		this.roleList = this.iRoleService.queryRoleInOrder(roleID, roleName);
		return "roleAuthorize";
	}
	
	/**
	 * 权限授权（角色用户、角色菜单）初始化
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-7-26
	 */
	public String initialAuthorizeList() throws Exception {
		//携带角色授权信息roleUID
		return "authorizeList";
	}
	
	/**
	 * @return the iRoleService
	 */
	@JSON(serialize=false)
	public IRoleService getiRoleService() {
		return iRoleService;
	}
	
	/**
	 * @param iRoleService the iRoleService to set
	 */
	public void setiRoleService(IRoleService iRoleService) {
		this.iRoleService = iRoleService;
	}

	/**
	 * @return the iRoleMenuService
	 */
	@JSON(serialize=false)
	public IRoleMenuService getiRoleMenuService() {
		return iRoleMenuService;
	}

	/**
	 * @param iRoleMenuService the iRoleMenuService to set
	 */
	public void setiRoleMenuService(IRoleMenuService iRoleMenuService) {
		this.iRoleMenuService = iRoleMenuService;
	}

	/**
	 * @return the iUserRoleService
	 */
	@JSON(serialize=false)
	public IUserRoleService getiUserRoleService() {
		return iUserRoleService;
	}

	/**
	 * @param iUserRoleService the iUserRoleService to set
	 */
	public void setiUserRoleService(IUserRoleService iUserRoleService) {
		this.iUserRoleService = iUserRoleService;
	}

	/**
	 * @return the iBasicResourceCascadeMgrService
	 */
	@JSON(serialize=false)
	public IBasicResourceCascadeMgrService getiBasicResourceCascadeMgrService() {
		return iBasicResourceCascadeMgrService;
	}

	/**
	 * @param iBasicResourceCascadeMgrService the iBasicResourceCascadeMgrService to set
	 */
	public void setiBasicResourceCascadeMgrService(
			IBasicResourceCascadeMgrService iBasicResourceCascadeMgrService) {
		this.iBasicResourceCascadeMgrService = iBasicResourceCascadeMgrService;
	}

	/**
	 * @return the roleID
	 */
	public String getRoleID() {
		return roleID;
	}

	/**
	 * @param roleID the roleID to set
	 */
	public void setRoleID(String roleID) {
		this.roleID = roleID;
	}

	/**
	 * @return the roleName
	 */
	public String getRoleName() {
		return roleName;
	}

	/**
	 * @param roleName the roleName to set
	 */
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	/**
	 * @return the roleList
	 */
	public List<IRole> getRoleList() {
		return roleList;
	}

	/**
	 * @param roleList the roleList to set
	 */
	public void setRoleList(List<IRole> roleList) {
		this.roleList = roleList;
	}

	/**
	 * @return the roleUID
	 */
	public String getRoleUID() {
		return roleUID;
	}

	/**
	 * @param roleUID the roleUID to set
	 */
	public void setRoleUID(String roleUID) {
		this.roleUID = roleUID;
	}

	/**
	 * @return the role
	 */
	public IRole getRole() {
		return role;
	}

	/**
	 * @param role the role to set
	 */
	public void setRole(IRole role) {
		this.role = role;
	}
	
}
